package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.feign.SystemLogClient;
import org.dromara.system.api.domain.bo.RemoteLogininforBo;
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:23
 * @version: v1
 */
@Slf4j
@Component
public class SystemLogFallBack implements FallbackFactory<SystemLogClient> {

    @Override
    public SystemLogClient create(Throwable throwable) {
        log.error("SystemLogFallBack, cause:{}", throwable.getMessage());
        return new SystemLogClient() {

            @Override
            public R<Void> saveLog(RemoteOperLogBo remoteOperLogBo) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }

            @Override
            public R<Void> saveLogininfor(RemoteLogininforBo remoteLogininforBo) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }
        };
    }

}
